package com.peng.controller;

import com.peng.Main;
import com.peng.model.TActivity;
import com.peng.model.TDicValue;
import com.peng.model.TProduct;
import com.peng.result.DicEnum;
import com.peng.result.R;
import com.peng.service.TDicValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DicController {

    @GetMapping(value = "/api/dicValue/{type_code}")
    public R dicData(@PathVariable(value = "type_code") String type_code) {
        if (type_code.equals(DicEnum.ACTIVITY.getCode())) { //activity
            List<TActivity> tActivityList = (List<TActivity>) Main.cacheMap.get(type_code);
            return R.OK(tActivityList);
        } else if (type_code.equals(DicEnum.PRODUCT.getCode())) {
            List<TProduct> tProductList = (List<TProduct>)Main.cacheMap.get(type_code);
            return R.OK(tProductList);
        } else {
            List<TDicValue> tDicValueList = (List<TDicValue>)Main.cacheMap.get(type_code);
            return R.OK(tDicValueList);
        }
    }
}
